package action;

import java.text.DateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import bean.Country;
import bean.Destination;
import bean.Status;
import bean.Travelogue;
import bean.User;
import dao.DestinationDAO;
import dao.StatusDAO;
import dao.TravelogueDAO;
import dao.UserDAO;
import form.DestinationForm;
import form.TravelogueForm;

public class UploadDestinationAction extends Action {
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,		
		HttpServletRequest request, HttpServletResponse response) {
		
		DestinationForm dform=(DestinationForm)form;
		String destName=dform.getDestinationName();
		String contryName=dform.getCountry();
		Float latitude=dform.getDLatitude();
		Float longtitude=dform.getDLongitude();
		String description=dform.getDescription();
		
		UserDAO userDAO=new UserDAO();
		DestinationDAO destDAO=new DestinationDAO();
		ActionErrors errors=new ActionErrors();
		//HttpSession session=request.getSession(false);

		    Country destCountry=new Country(contryName);
		    Destination newDestination=new Destination(destCountry, destName,description,latitude,longtitude);
		    if(newDestination!=null){
		    destDAO.save(newDestination);
		    //session.setAttribute("travelogue", newTravelogue);
		    return mapping.findForward("listDestination");
		}
		else{
			errors.add("notExist",new ActionMessage("Destination.notExist"));
		}
		
		saveErrors(request, errors);
		return mapping.getInputForward();
		
			
	}
}
